﻿namespace TestTool.GUI.Utils
{
    using System;
    using System.IO;
    using System.Text;
    using System.Xml;

    internal class XmlFragmentWriter : XmlTextWriter
    {
        private bool _start;

        public XmlFragmentWriter(Stream w) : base(w, Encoding.UTF8)
        {
            this._start = true;
        }

        public XmlFragmentWriter(TextWriter w) : base(w)
        {
            this._start = true;
        }

        public XmlFragmentWriter(Stream w, Encoding encoding) : base(w, encoding)
        {
            this._start = true;
        }

        public XmlFragmentWriter(string filename, Encoding encoding) : base(new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None), encoding)
        {
            this._start = true;
        }

        public override void WriteEndDocument()
        {
            base.WriteEndElement();
            base.WriteEndDocument();
        }

        public override void WriteStartDocument()
        {
            if (this._start)
            {
                base.WriteStartDocument();
                base.WriteStartElement("Advanced");
                this._start = false;
            }
        }
    }
}

